//
//  LFTabBarController.m
//  College
//
//  Created by LF on 2018/11/6.
//  Copyright © 2018 MuXi. All rights reserved.
//

#import "LFTabBarController.h"
#import "LFTabBar.h"

@interface LFTabBarController ()<LFTabBarDelegate>

@property (nonatomic, strong) NSArray *datas; /**< 数据 */
@property (nonatomic, strong) LFTabBar *tabBar_l; /**< tabBar */

@end

@implementation LFTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupControllers];
    
    self.tabBar.hidden = YES;
}

#pragma mark - setup
- (void) setupControllers {
    
    NSMutableArray *navs = [NSMutableArray array];
    
    for (int i = 0; i < self.datas.count ; i++) {
        [navs addObject:[self setupNav:self.datas[i]]];
    }
    
    [self.tabBar_l configTabbar:self.datas];
    [self.view addSubview:self.tabBar_l];
    [self.tabBar_l setMessageCount:5 atIndex:0];
    self.viewControllers = navs;
}

- (LFCustomNavigationController *) setupNav:(NSDictionary *)dic {
    LFBaseViewController *vc = [[NSClassFromString(dic[@"controller"]) alloc] init];
    vc.isTopVc = YES;
    LFCustomNavigationController *nav = [[LFCustomNavigationController alloc] initWithRootViewController:vc];
    nav.title = dic[@"title"];
    return nav;
}

#pragma mark - LFTabBarDelegate
- (void)didSelectedTabBarAtIndex:(NSInteger)index {
    self.selectedIndex = index;
}


- (NSArray *)datas {
    return @[
             @{
                 @"title":@"首页",
                 @"image":@"tab_img_home",
                 @"selectedImage":@"tab_img_home_selected",
                 @"controller":@"LFHomeViewController"
                 },
//             @{
//                 @"title":@"图书馆",
//                 @"image":@"tab_img_find",
//                 @"selectedImage":@"tab_img_find_selected",
//                 @"controller":@"LFHomeViewController"
//                 },
             @{
                 @"title":@"学习计划",
                 @"image":@"tab_img_dynamic",
                 @"selectedImage":@"tab_img_dynamic_selected",
                 @"controller":@"LFHomeViewController"
                 },
             @{
                 @"title":@"我",
                 @"image":@"tab_img_profile",
                 @"selectedImage":@"tab_img_profile_selected",
                 @"controller":@"LFProfileViewController"
                 }
             ];
}

- (LFTabBar *)tabBar_l {
    if (!_tabBar_l) {
        _tabBar_l = [LFTabBar sharedTabBar];
        _tabBar_l.delegate = self;
    }
    return _tabBar_l;
}

@end
